package com.prolificinteractive.materialcalendarview.sample.decorators;

import ohos.agp.components.element.Element;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.render.Canvas;

import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;

import org.threeten.bp.DayOfWeek;

/**
 * Highlight Saturdays and Sundays with a background
 */
public class HighlightWeekendsDecorator implements DayViewDecorator {
    private final Element highlightDrawable;
    private static final int color = 0x228BC34A;

    public HighlightWeekendsDecorator() {
        highlightDrawable = new ShapeElement() {
            @Override
            public void drawToCanvas(Canvas canvas) {
                canvas.drawColor(color, Canvas.PorterDuffMode.SRC_ATOP);
            }
        };
    }

    @Override
    public boolean shouldDecorate(final CalendarDay day) {
        final DayOfWeek weekDay = day.getDate().getDayOfWeek();
        return weekDay == DayOfWeek.SATURDAY || weekDay == DayOfWeek.SUNDAY;
    }

    @Override
    public void decorate(final DayViewFacade view) {
        view.setBackgroundDrawable(highlightDrawable);
    }
}
